local xuanzhushi = fk.CreateSkill{
  name = "lzsj__xuanzhushi",
  tags = { "Phase" },
}

Fk:loadTranslationTable{
  ["lzsj__xuanzhushi"] = "旋诸势",
  [":lzsj__xuanzhushi"] = "阶段技，出牌阶段，你可令一名其他角色将每个区域各一张牌当一张非【毒】基本牌对你使用（其选择）；然后你可展示其一张手牌，若与转化底牌花色均不同，之无效。",
  ["#lzsj__xuanzhushi"] = "你可以选择一名其他角色，其将每个区域各一张牌当一张基本牌对你使用",
  ["#lzsj__xuanzhushi-choose"] = "请选择每个区域各一张牌",
  ["#lzsj__xuanzhushi-show"] = "你可以展示%src一张手牌",
  ["$lzsj__xuanzhushi1"] = "进了山海关，都得给我交买路钱！",
  ["$lzsj__xuanzhushi2"] = "那江湖不是打打杀杀，那江湖是人情世故~",
}

local U = require "packages/utility/utility"

xuanzhushi:addEffect("active", {
  anim_type = "control",
  prompt = "#lzsj__xuanzhushi",
  max_phase_use_time = 1,
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player and not to_select:isAllNude()
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local cards = U.askforCardsChosenFromAreas(target, target, "hej", xuanzhushi.name, "#lzsj__xuanzhushi-choose", {}, false)
    if #cards > 0 then
      local all_names = table.filter(Fk:getAllCardNames("b"), function (name) return not string.find(name, "poison") end)
      local names = table.filter(all_names, function (name) return target:canUseTo(Fk:cloneCard(name), player, {bypass_distances = true}) end)
      local choice = room:askToChoice(target, { choices = names, skill_name = xuanzhushi.name, all_choices = all_names })
      room:useVirtualCard(choice, cards, target, player, xuanzhushi.name, true)
    end
  end,
})

xuanzhushi:addEffect(fk.CardUsing, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(xuanzhushi.name) and data.card.skillName == xuanzhushi.name
    and not data.from:isKongcheng()
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = xuanzhushi.name, prompt = "#lzsj__xuanzhushi-show:"..data.from.id })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = table.random(data.from:getCardIds("h"), 1)
    data.from:showCards(ids)
    if not table.find(room:getSubcardsByRule(data.card), function (id)
      return Fk:getCardById(id):compareSuitWith(Fk:getCardById(ids[1])) end) then
      data.toCard = nil
      data:removeAllTargets()
    end
  end,
})

return xuanzhushi